package br.com.j7.jdesk.library.util;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {

	public static String slashify(String path, boolean isDirectory) {
		String p = path;
		
		if (File.separatorChar != '/')
			p = p.replace(File.separatorChar, '/');
		if (!p.startsWith("/"))
			p = "/" + p;
		if (!p.endsWith("/") && isDirectory)
			p = p + "/";
		return p;
	}

	public static Boolean find(String target, String regex) {
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(target);
		return m.find();
	}
	
	public static String clear(String str){
		str = str.trim();
		str = str.replaceAll("\n","");
		str = str.replaceAll("\t","");
		str = str.replaceAll("\r","");
		str.trim();
		return str;
	}	
}
